<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <h2 class="title"></h2>
  <button class="btn">改变文本</button>
  <script>
    // 1.定义数据
    let message = 'Hello World'

    //2. 将数据显示在h2元素中
    let title = document.getElementsByClassName('title')[0]
    title.innerHTML = message

    // 3.点击按钮,界面的数据发生改变
    let btn = document.getElementsByClassName('btn')[0]
    btn.addEventListener('click', e => {
      // 修改消息 
      message = 'Hello React'
      title.innerHTML = message
    })
  </script>
</body>

</html>